package com.quick.develop.flowable.controller.process;

import com.quick.develop.flowable.domain.vo.rule.BpmRuleReqVO;
import com.quick.develop.framework.common.page.R;
import com.quick.develop.flowable.application.IBpmRuleApplication;
import com.quick.develop.flowable.domain.rule.BpmProcessRule;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author junyuan.liu
 * @description:
 * @date 2022/5/18 18:30
 */
@Api(tags = "流程管理后台 - 流程规则")
@RestController
@RequestMapping("/proc-rule")
@Validated
public class BpmProcessRuleController  {
    @Resource
    IBpmRuleApplication bpmRuleApplication;

    @GetMapping("/get-rules")
    @ApiOperation(value = "获得流程规则信息")
    public R<?> getBpmProcessRules(BpmRuleReqVO reqVo){
        return R.ok(bpmRuleApplication.getBpmProcessRules(reqVo));
    }

    @PostMapping("/edit")
    @ApiOperation(value = "编辑流程规则")
    public R<?> handelBpmProcessRules(@RequestBody List<BpmProcessRule> list){
        bpmRuleApplication.handleBpmProcessRules(list);
        return R.ok();
    }

    @GetMapping("/getFirstNodeRule")
    @ApiOperation(value = "获取第一个节点规则")
    public R<?> getFirstNodeRule(@RequestParam("key")  String key){
        return R.ok(bpmRuleApplication.getFirstNodeRule(key));
    }

    @PostMapping("/get-bpm-rule")
    @ApiOperation(value = "获取流程规则")
    public R<?> getBpmRule(@RequestBody BpmRuleReqVO reqVo){
        return R.ok(bpmRuleApplication.getBpmRule(reqVo));
    }

    @GetMapping("/getRulesSetUp")
    @ApiOperation(value = "获得流程规则信息")
    public R<?> getBpmProcessRules4SetUp(BpmRuleReqVO reqVo){
        return R.ok(bpmRuleApplication.getBpmProcessRules4SetUp(reqVo));
    }

    @GetMapping("/get/rule/task/{modelKey}/{nodeKey}")
    @ApiOperation(value = "获取流程规则")
    public R<BpmProcessRule> getBpmRuleByModelKey(@PathVariable(value = "modelKey") String modelKey,@PathVariable(value = "nodeKey")String nodeKey){
        BpmProcessRule taskRule = bpmRuleApplication.getTaskRule(modelKey, nodeKey);
        return R.ok(taskRule);
    }

    @GetMapping("/get/rule/task/getRuleList/{modelKey}")
    @ApiOperation(value = "获取流程规则list")
    public R<List<BpmProcessRule>> getRuleList(@PathVariable(value = "modelKey") String modelKey){
        BpmRuleReqVO reqVO = new BpmRuleReqVO();
        reqVO.setModelKey(modelKey);
        return R.ok(bpmRuleApplication.getBpmProcessRulesList(reqVO));
    }
}
